#ifndef _USER_FIFO_H_
#define _USER_FIFO_H_

#include <stdint.h>


typedef struct
{
    uint8_t X_H;
    uint8_t X_L;
    uint8_t Y_H;
    uint8_t Y_L;
    uint8_t Z_H;
    uint8_t Z_L;
}Accel_Byte;

typedef struct
{
    uint8_t X_H;
    uint8_t X_L;
    uint8_t Y_H;
    uint8_t Y_L;
    uint8_t Z_H;
    uint8_t Z_L;
}Gyro_Byte;


typedef struct
{
    uint8_t X_H;
    uint8_t X_L;
    uint8_t Y_H;
    uint8_t Y_L;
    uint8_t Z_H;
    uint8_t Z_L;
}Euler_Byte;

typedef struct
{
    int16_t X;
    int16_t Y;
    int16_t Z;
}Accel_Short;

typedef struct
{
    int16_t X;
    int16_t Y;
    int16_t Z;
}Gyro_Short;


typedef struct
{
    int16_t roll;
    int16_t pitch;
    int16_t yaw;
}Euler_Short;

typedef struct
{
//    Accel_Byte accel;
//    Gyro_Byte gyro;
//    Euler_Byte euler;
    Accel_Short accel;
    Gyro_Short  gyro;
    Euler_Short euler;
    uint16_t sum;
}Data_packet;

typedef union
{
    uint8_t data_byte[20];
    Data_packet packet;
}Data_packet_t;

typedef struct
{
    Data_packet_t * packet;
    uint16_t        max_buf_size;
    uint16_t        length;
    volatile uint32_t  read_pos;
    volatile uint32_t  write_pos;
}array_fifo_t;


void array_fifo_init(array_fifo_t *fifo, Data_packet_t *buf, uint16_t buf_size);
int push_data(array_fifo_t *fifo, Data_packet_t *p_buf);
int pop_data(array_fifo_t *fifo, Data_packet_t *buf);
uint16_t get_buf_count(array_fifo_t *fifo);


#endif
